package com.itheima.controller;

import com.itheima.pojo.PageResult;
import com.itheima.pojo.Result;
import com.itheima.pojo.Student;
import com.itheima.pojo.StudentQueryParam;
import com.itheima.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/students")
public class StudentController {

    @Autowired
    private StudentService studentService;

    // 学生分页查询
    @GetMapping
    public Result page(StudentQueryParam studentQueryParam){
        log.info("学生分页查询请求参数 {}", studentQueryParam);
        PageResult pageResult = studentService.page(studentQueryParam);
        return Result.success(pageResult);
    }

    // 根据ID删除学生
    @DeleteMapping("/{ids}")
    public Result delete(@PathVariable List<Integer> ids){
        log.info("根据ID删除班级: {}", ids);
        studentService.delete(ids);
        return Result.success();
    }

    // 添加员工
    @PostMapping
    public Result save(@RequestBody Student student){
        log.info("新增学生: {}", student);
        studentService.save(student);
        return Result.success();
    }

    // 根据ID查询
    @GetMapping("/{id}")
    public Result getInfo(@PathVariable Integer id){
        log.info("根据ID查询: ", id);
        Student student = studentService.getInfo(id);
        return Result.success(student);
    }

    // 修改学员信息
    @PutMapping
    public Result update(@RequestBody Student student){
        log.info("修改员工: {}", student);
        studentService.update(student);
        return Result.success();
    }

    // 违纪处理
    @PutMapping("/violation/{id}/{score}")
    public Result violationHandle(@PathVariable Integer id, @PathVariable Integer score){
        studentService.violationHandle(id, score);
        return Result.success();
    }

}
